package com.perfect.mybatis.config;

import com.perfect.mybatis.spring.PerfectMapperScanner;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author chenshiping
 * @date 2025/3/14
 * @description TODO
 */
@Configuration
@ComponentScan(basePackages = "com.perfect")
@PerfectMapperScanner(basePackage = "com.perfect.mybatis.mapper")
public class AppConfig {


    @Bean
    public SqlSessionFactory sqlSessionFactory() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("mybatis.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        return sqlSessionFactory;
    }
}
